package com.stylefeng.guns.modular.small.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.modular.small.util.ResponseResultDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.small.model.BizConsumer;
import com.stylefeng.guns.modular.small.service.IBizConsumerService;

import java.util.Date;

/**
 * 小程序端消费者控制器
 *
 * @author fengshuonan
 * @Date 2019-09-08 00:32:58
 */
@Controller
@RequestMapping("/bizConsumer")
public class BizConsumerController extends BaseController {

    private String PREFIX = "/small/bizConsumer/";

    @Autowired
    private IBizConsumerService bizConsumerService;

    /**
     * 跳转到小程序端消费者首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "bizConsumer.html";
    }

    /**
     * 跳转到添加小程序端消费者
     */
    @RequestMapping("/bizConsumer_add")
    public String bizConsumerAdd() {
        return PREFIX + "bizConsumer_add.html";
    }

    /**
     * 跳转到修改小程序端消费者
     */
    @RequestMapping("/bizConsumer_update/{bizConsumerId}")
    public String bizConsumerUpdate(@PathVariable Integer bizConsumerId, Model model) {
        BizConsumer bizConsumer = bizConsumerService.selectById(bizConsumerId);
        model.addAttribute("item",bizConsumer);
        LogObjectHolder.me().set(bizConsumer);
        return PREFIX + "bizConsumer_edit.html";
    }

    /**
     * 获取小程序端消费者列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return bizConsumerService.selectList(null);
    }

    /**
     * 新增小程序端消费者
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(BizConsumer bizConsumer) {
        bizConsumerService.insert(bizConsumer);
        return SUCCESS_TIP;
    }

    /**
     * 删除小程序端消费者
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer bizConsumerId) {
        bizConsumerService.deleteById(bizConsumerId);
        return SUCCESS_TIP;
    }

    /**
     * 修改小程序端消费者
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(BizConsumer bizConsumer) {
        ResponseResultDTO  responseResultDTO=new ResponseResultDTO();
        bizConsumer.setUpdateDate(new Date());
        bizConsumerService.updateById(bizConsumer);
        BizConsumer  consumer= bizConsumerService.selectById(bizConsumer.getId());
        responseResultDTO.setData(consumer);
        return responseResultDTO;
    }

    /**
     * 小程序端消费者详情
     */
    @RequestMapping(value = "/detail/{bizConsumerId}")
    @ResponseBody
    public Object detail(@PathVariable("bizConsumerId") Integer bizConsumerId) {
        return bizConsumerService.selectById(bizConsumerId);
    }
}
